<?php

 /**
  * @package JooS
  * @subpackage Syntax
  */

  abstract class JooS_Syntax_Abstract {
    protected static $_phpReservedWords = array(
      "abstract", "and", "array", "as", "break", "case", "catch", "class", "clone", "const", 
      "continue", "declare", "default", "do", "else", "elseif", "enddeclare", "endfor", 
      "endforeach", "endif", "endswitch", "endwhile", "extends", "final", "for", "foreach", 
      "function", "global", "goto", "if", "implements", "interface", "instanceof", "namespace", 
      "new", "or", "private", "protected", "public", "static", "switch", "throw", "try", "use", 
      "var", "while", "xor", 

      "__CLASS__", "__DIR__", "__FILE__", "__FUNCTION__", "__METHOD__", "__NAMESPACE__", 

      "die", "echo", "empty", "exit", "eval", "include", "include_once", "isset", "list", 
      "require", "require_once", "return", "print", "unset", 
    );

    protected $_parsedValue = null;

    /**
     * @var JooS_Syntax_Compiler
     */
    private $_parser = null;

    abstract public function compile();

    public function init() {
    }

    /**
     * @param JooS_Syntax_Compiler $parser
     * @return JooS_Syntax_Abstract
     */
    public function setParser(JooS_Syntax_Compiler $parser) {
      $this->_parser = $parser;
      return $this;
    }

    /**
     * @return JooS_Syntax_Compiler
     */
    protected function getParser() {
      return $this->_parser;
    }

    /**
     * @return string
     */
    public function compileSyntax() {
      $this->_parsedValue = $this->compile();
      return $this->_parsedValue;
    }

    /**
     * @return string
     */
    public function getParsedValue() {
      return $this->_parsedValue;
    }

    /**
     * @param string $name
     * @return JooS_Syntax_Abstract
     */
    protected function createSyntax($name) {
      $arguments = func_get_args();
      array_shift($arguments);

      $syntax = $this->_parser->createSyntax($name);
      
      call_user_func_array(
        array( $syntax, "init" ), array_values($arguments)
      );
      return $syntax;
    }

    /**
     * @param int $count
     * @param bool $shift
     * @return string
     */
    protected function substr($count, $shift = false) {
      return $this->_parser->substr($count, $shift);
    }
  }
